<?php

class Application_Model_User implements Zend_Acl_Role_Interface {

    protected $_real_name;
    protected $_password;
    protected $_username;
    protected $_email;
    protected $_role;
    protected $_id;
    protected $_aclRoleId = null;

    public function getRoleId() {
        if ($this->_aclRoleId == null) {
            return 'guest';
        }

        return $this->_aclRoleId;
    }

    public function __construct(array $options = null) {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value) {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        $this->$method($value);
    }

    public function __get($name) {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        return $this->$method();
    }

    public function setOptions(array $options) {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }

    public function setUsername($username) {
        $this->_username = str_replace('\\', '', (string) $username);
        return $this;
    }

    public function getUsername() {
        return $this->_username;
    }

    public function setRole($role) {
        $this->_role = (string) $role;
        return $this;
    }

    public function getRole() {
        return $this->_role;
    }

    public function setPassword($password) {
        $this->_password = (string) $password;
        return $this;
    }

    public function getPassword() {
        return $this->_password;
    }

    public function setRealName($realname) {
        $this->_real_name = str_replace('\\', '', (string) $realname);
        return $this;
    }

    public function getRealName() {
        return $this->_real_name;
    }

    public function setId($id) {
        $this->_id = (int) $id;
        return $this;
    }

    public function getId() {
        return $this->_id;
    }

    public function setEmail($email) {
        $this->_email = $email;
        return $this;
    }

    public function getEmail() {
        return $this->_email;
    }

}

